<?php

namespace App\Http\Controllers\Api\V3;

use App\Common\ApiData;
use App\Models\V1\LearningOfficerMatter;
use App\Models\V1\LessonCenter;
//use Dingo\Api\Routing\Helpers;
use App\Models\V1\Lessons;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Http\Response;

class LearningOfficerMatterController extends BaseController
{
//    use Helpers;
    /**
     * @var ApiData
     */
    private $apiData;

    public function __construct(ApiData $apiData)
    {

        $this->apiData = $apiData;
    }

    /**
     * @param LearningOfficerMatter $learningOfficerMatter
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(LearningOfficerMatter $learningOfficerMatter)
    {
        $article = $learningOfficerMatter->get_article_data();
        return $this->apiData->set_data('articleData', $article)->send(200, 'success');
    }

    public function get_article_detail(Request $request, LearningOfficerMatter $learningOfficerMatter)
    {
        $articleId = $request->articleId;
        $user_phone = $request->userPhone;

        $data = $learningOfficerMatter->get_article_comment_data($articleId, $user_phone);
        return $this->apiData->set_data('article', $data)->send(200, 'success');
    }

    /**
     * 获取某一个文章分类下面的所有的文章
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @internal param $lessonsCategoryId
     */
    public function show(Request $request)
    {
        $lessonsCategoryId = $request->lessonsCategoryId;

        $lessonsArticleCategoryData = LearningOfficerMatter::where('lessons_category_id', $lessonsCategoryId)->paginate(4);

        $data = collect($lessonsArticleCategoryData)->toArray();
        //对分类下面的文章添加内容链接
        foreach ($data['data'] as $k => &$v) {
            $v['contentLink'] = url("api/v3/share/{$v['id']}");
        }

        if ($data) {
            return $this->apiData->set_data('articleCategoryData', $data)->send(200, '获取数据成功');
        }
        return $this->apiData->set_data()->send('300', '获取数据失败');
    }
}


















